﻿#ifndef XPUSHBUTTON_H
#define XPUSHBUTTON_H

#include <QObject>
#include "xpushbuttonfunction.h"
#include "xnamespace.h"

QT_BEGIN_NAMESPACE

class XPushButtonPrivate;
class XPushButton : public XPushButtonFunction
{
    Q_OBJECT

    Q_PROPERTY(XCoil *objectXCoil READ getObjectXCoil WRITE setObjectXCoil)
    Q_PROPERTY(PushButtonOperate pushButtonOperate READ getPushButtonOperate WRITE setPushButtonOperate)
    Q_PROPERTY(bool delayEnable READ getDelayEnable WRITE setDelayEnable)
    Q_PROPERTY(NumberType delayType READ getDelayType WRITE setDelayType)
    Q_PROPERTY(XRegister *delayTimeRegister READ getDelayTimeRegister WRITE setDelayTimeRegister)
    Q_PROPERTY(int delayTimeConstant READ getDelayTimeConstant WRITE setDelayTimeConstant)

public:
    explicit XPushButton(QWidget *parent = nullptr);
    ~XPushButton();

    XCoil *getObjectXCoil() const;
    void setObjectXCoil(XCoil *xCoil);

    PushButtonOperate getPushButtonOperate() const;
    void setPushButtonOperate(PushButtonOperate operate);

    bool getDelayEnable() const;
    void setDelayEnable(bool);

    NumberType getDelayType() const;
    void setDelayType(NumberType type);

    XRegister *getDelayTimeRegister() const;
    void setDelayTimeRegister(XRegister *xRegister);

    int getDelayTimeConstant() const;
    void setDelayTimeConstant(int);

protected:
    void paintEvent(QPaintEvent *ev) override;

    void mousePressEvent(QMouseEvent *ev) override;

private:
    Q_DISABLE_COPY(XPushButton)
    XPushButtonPrivate *xPushButtonP = nullptr;

    //    XFunction xFunction;
    Function func = nullptr;
    void updateOperate(int pattern);
};

QT_END_NAMESPACE

#endif // XPUSHBUTTON_H
